//
//  TeamRandomDetailsViewController.m
//  YXFinance
//
//  Created by uplooking on 2018/10/25.
//  Copyright © 2018年 CRLong. All rights reserved.
//

#import "TeamRandomDetailsViewController.h"

@interface TeamRandomDetailsViewController ()
{
    
    UIScrollView * scrollView;
    UIImageView * topImageView;
    TeacherIndexModel * teacherModel;
}

@end

@implementation TeamRandomDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setBackLeftBarButtonItemAction:@selector(backAction:)];
    [self startSKV];
    [self getTeacherDetailsData];
}

- (void)backAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)initView{
    
    self.title = teacherModel.teacher_name;
    
    UIView * topView = [[UIView alloc]init];
    [self.view addSubview:topView];
    [topView setBackgroundColor:[UIColor whiteColor]];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.view);
        make.height.mas_equalTo(70 * kAutoScanleX);
    }];
    
    UIButton * registerBtn=[[UIButton alloc]init];
    [registerBtn setBackgroundColor:HexRGBA(0xb99c6d, 1)];
    [registerBtn addTarget:self action:@selector(registerBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [registerBtn.layer setMasksToBounds:YES];
    [registerBtn.layer setCornerRadius:8.0 * kAutoScanleX];
    [registerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [registerBtn setTitle:@"立即报名" forState:UIControlStateNormal];
    [registerBtn.titleLabel setFont:[UIFont systemFontOfSize:16 * kAutoScanleX]];
    [topView addSubview:registerBtn];
    [registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(topView);
        make.height.mas_equalTo(45 * kAutoScanleX);
        make.centerX.equalTo(topView);
        make.width.mas_equalTo(576/2.0 * kAutoScanleX);
    }];
    
    
    scrollView=[[UIScrollView alloc]init];
    [self.view addSubview:scrollView];
    [scrollView setShowsHorizontalScrollIndicator:NO];
    [scrollView setShowsVerticalScrollIndicator:NO];
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.bottom.equalTo(topView.mas_top);
    }];
    
    
    UIView *vContainer = [UIView new];
    [scrollView addSubview:vContainer];
    [vContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(scrollView);
        make.width.equalTo(scrollView);
    }];

    UIImageView * topImageView = [[UIImageView alloc]init];
    topImageView.clipsToBounds = YES;
    topImageView.contentMode =  UIViewContentModeScaleAspectFill;
    [vContainer addSubview:topImageView];
    [topImageView sd_setImageWithURL:[NSURL URLWithString:teacherModel.top_image]placeholderImage:[UIImage imageNamed:@"img_daoshi_xiangqing_morentu"]];
    [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(vContainer);
        make.height.mas_equalTo(800 * kAutoScanleX);
    }];

    UIView * infoView = [[UIView alloc]init];
    [infoView setBackgroundColor:[UIColor whiteColor]];
    [vContainer addSubview:infoView];
    [infoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topImageView.mas_bottom);
        make.left.right.equalTo(vContainer);
    }];
    
    
    
    UILabel * labelTitle = [[UILabel alloc]init];
    [labelTitle setText:@"导师介绍"];
    [labelTitle setTextColor:HexRGBA(0x000000, 1)];
    [labelTitle setFont:[UIFont systemFontOfSize:18 * kAutoScanleX]];
    [labelTitle setTextAlignment:NSTextAlignmentLeft];
    [infoView addSubview:labelTitle];
    [labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(infoView);
        make.top.equalTo(infoView).offset(30 * kAutoScanleX);
    }];
    

    
    UILabel * labelContent = [[UILabel alloc]init];
    [labelContent setNumberOfLines:0];
    [labelContent initWithString:teacherModel.teacher_intro spacing:6 * kAutoScanleX];
    [labelContent setTextColor:HexRGBA(0x000000, 1)];
    [labelContent setFont:[UIFont systemFontOfSize:15 * kAutoScanleX]];
    [labelContent setTextAlignment:NSTextAlignmentLeft];
    [infoView addSubview:labelContent];
    [labelContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(infoView).offset(125 * kAutoScanleX);
        make.top.equalTo(labelTitle.mas_bottom).offset(30 * kAutoScanleX);
        make.right.equalTo(infoView).offset(-15 * kAutoScanleX);
    }];
    
    
    UIImageView * iconImage = [[UIImageView alloc]init];
    [infoView addSubview:iconImage];
    [iconImage.layer setMasksToBounds:YES];
    [iconImage.layer setCornerRadius:75/2.0 * kAutoScanleX];
    [iconImage sd_setImageWithURL:[NSURL URLWithString:teacherModel.icon] placeholderImage:[UIImage imageNamed:@"icon_pinglun_touxiang"]];
    [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(infoView).offset(35 * kAutoScanleX);
        make.centerY.equalTo(labelContent);
        make.size.mas_equalTo(CGSizeMake(75 * kAutoScanleX, 75 * kAutoScanleX));
    }];
    
    [infoView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(labelContent).offset(40 * kAutoScanleX);
    }];
    
    [vContainer mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(infoView);
    }];
    
    
}

#pragma mark -- 立即报名
- (void)registerBtnAction:(UIButton *)sender{
    
    WS(weakSelf);
    //判断是否登录，没登录跳转
    BOOL isLogin=[LoginCorrelationHelper loginCorrelationHelperIsLogin];
    [[LoginCorrelationHelper shareInstance] setLoginFinishBlock:^{
        [weakSelf registerBtnAction:sender];
    }];
    if (!isLogin) return;
    
    
    LoginProtocolViewController * vc = [[LoginProtocolViewController alloc]init];
    
    [self.navigationController pushViewController:vc animated:YES];
    
}

#pragma mark -- 详情
- (void)getTeacherDetailsData{
    
    WS(weakSelf);
    [HttpRequestHelper requestApiTeacherId:_teacher_id Block:^(NSString *msg, TeacherIndexModel *indexModel) {
       
        [weakSelf stopSKV];
        [weakSelf hideHud];
        
        if (REQUEST_SUCCESS) {
            
            teacherModel = indexModel;
            [weakSelf initView];
            
        }else{
         
            [weakSelf showHint:msg];
        }
    }];
    
    
}


@end
